const mongoose = require('mongoose');


const searchSeats = async ({ theaterId, row, col }) => {
    const data = await mongoose.model("seats").find({ theaterId });
    if (data.length) {
        return data
    } else {
        await addNewSeats({ theaterId, row, col });
        await searchSeats({ theaterId })
    }
}



const addNewSeats = async ({ theaterId, row, col }) => {
    for (let i = 0; i < row; i++) {
        for (let j = 0; j < col; j++) {
            await mongoose.model("seats").create({ row: ~~i + 1, col: ~~j + 1, theaterId });
        }
    }
}




module.exports = { searchSeats }